/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018年5月30日 下午9:12:38
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */  
package com.github.wxpay.sdk;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**   
 * @ClassName:  WxConfig
 * @author: 迷蝶
 * @date:   2018年5月30日 下午9:12:38 
 *     
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
public class WxConfig extends WXPayConfig{

    private byte[] certData;
    private static WxConfig INSTANCE;

    private WxConfig() throws Exception{
        String certPath = "D:/userdata/gshop/apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WxConfig getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WxConfig.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WxConfig();
                }
            }
        }
        return INSTANCE;
    }

    public String getAppID() {
        return "wx24eb520310b782ab";
    }

    public String getMchID() {
        return "1505232361";
    }

    public String getKey() {
        return "f76d9f797192e69fe595af2765de927a";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    @Override
    public int getReportWorkerNum() {
        return 1;
    }

    @Override
    public int getReportBatchSize() {
        return 2;
    }
}
